home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / modules / hackdisk.asm < prev    next >
Assembly Source File  |  2000-02-16  |  6KB  |  254 lines

  1. ; FILE: Source:modules/hackdisk.ASM          REV: 25 --- Install hackdisk.device
  2.  
  3. ;
  4. ; Plant hackdisk.device -Module
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This patch module will plant hackdisk.device into current ROM image, so
  7. ; replacing trackdisk.device.
  8. ;
  9. ; Device will be loaded from file "devs:hackdisk.device".
  10. ;
  11. ; hackdisk.device is copyright © 1992,93 by Dan Babcock.
  12. ; Version 2.04 is copyright © 1996-1997 by Harry Sintonen. =o)
  13. ;
  14. ; Actually, version 2.04 of hackdisk.device was "made" (haha!) by me
  15. ; to be compatible with BlizKick. Version 2.02 had a bug which caused
  16. ; it to fail when used with this module (it tried to open
  17. ; intuition.library before it was even initialized. I had to modify it,
  18. ; because changing trackdisk.device's residenttag priority would have
  19. ; been too hackish. Trackdisk (and hackdisk!) has priority 20 and
  20. ; intuition has 10).
  21. ;
  22. ; This module has been tested with version 2.04.
  23. ;
  24. ; Please note that not all devices and libraries can be "fixed" to
  25. ; be "resident"... Maybe some future BlizKick release will allow you
  26. ; to make any pure device or library resident... Maybe...
  27. ;
  28. ; Written by Harry Sintonen.
  29. ; This source code is Public Domain.
  30. ;
  31.  
  32.     incdir    "include:"        ; Some required...
  33.     include    "exec/types.i"
  34.     include    "exec/libraries.i"
  35.     include    "blizkickmodule.i"
  36.  
  37. _LVOAllocMem    EQU    -$C6
  38. _LVOFreeMem    EQU    -$CC
  39. _LVOCopyMem    EQU    -$270
  40.  
  41. _LVOOpen    EQU    -$1E
  42. _LVOClose    EQU    -$24
  43. _LVORead    EQU    -$2A
  44. _LVOSeek    EQU    -$42
  45. _LVOInternalLoadSeg    EQU    -$2F4        ; 2.0+
  46. _LVOInternalUnLoadSeg    EQU    -$2FA
  47.  
  48. MODE_OLDFILE    EQU    1005
  49. OFFSET_CURRENT    EQU    0
  50. HUNK_RELOC32    EQU    1004
  51.  
  52. call    MACRO
  53.     jsr    (_LVO\1,a6)
  54.     ENDM
  55.  
  56.     SECTION    PATCH,CODE
  57. _DUMMY_LABEL
  58.     BK_PTC
  59.  
  60. ; Code is run with following incoming parameters:
  61. ;
  62. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  63. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  64. ; d0=ROM lenght in bytes    eg. $00080000
  65. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  66. ;    CALL: jsr (a2)
  67. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  68. ;     OUT: d0=ptr to resident (buf) or NULL
  69. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  70. ;    CALL: jsr (a3)
  71. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  72. ;     OUT: d0=success
  73. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  74. ;    CALL: jsr (a4)
  75. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  76. ;     OUT: -
  77. ; d6=dosbase, a6=execbase
  78. ;
  79. ; Code should return:
  80. ;
  81. ; d0=true if succeeded, false if failed.
  82. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  83.  
  84.  
  85. ; NOTE: Kickstart *is* 2.0+
  86.  
  87.     cmp.w    #33,($C,a0)        ; Requires KS ROM V1.2+
  88.     bhs.b    .go
  89.     moveq    #0,d0
  90.     rts
  91.  
  92. .go    movem.l    d0/a0-a1,-(sp)
  93.     moveq    #0,d7
  94.  
  95.     lea    (_tdname,pc),a1        ; _FindResident
  96.     jsr    (a2)
  97.     tst.l    d0
  98.     beq    .xit
  99.     move.l    d0,a5            ; a5=trackdisk resident
  100.  
  101.     moveq    #1,d7
  102.     move.l    (RT_IDSTRING,a5),a0
  103.     sub.l    (2*4,sp),a0
  104.     add.l    (1*4,sp),a0
  105.     lea    (_hdiname,pc),a1    ; NOTE: lowercase!
  106.     moveq    #8-1,d1            ; 'hackdisk'
  107. .cmp    move.b    (a0)+,d0
  108.     or.b    #32,d0            ; lowercase
  109.     cmp.b    (a1)+,d0
  110.     dbne    d1,.cmp
  111.     tst.w    d1            ; Test if already installed
  112.     bmi    .xit
  113.  
  114.     moveq    #0,d7
  115.     exg    d6,a6
  116.     lea    (_hddname,pc),a0
  117.     move.l    a0,d1
  118.     move.l    #MODE_OLDFILE,d2
  119.     call    Open
  120.     move.l    d0,d4
  121.     beq    .exit
  122.  
  123.     sub.l    a0,a0
  124.     lea    (funcs,pc),a1
  125.     subq.l    #4,sp
  126.     move.l    sp,a2
  127.     call    InternalLoadSeg
  128.     addq.l    #4,sp
  129.     move.l    d0,d5
  130.     beq    .close
  131.     bmi    .baddie
  132.  
  133.     move.l    d5,a2
  134.     add.l    a2,a2
  135.     add.l    a2,a2
  136.     tst.l    (a2)+            ; Requires single hunk exe!
  137.     bne    .baddie            ; a2=hunk start
  138.  
  139.     move.l    (RT_ENDSKIP,a2),d1
  140.     sub.l    a2,d1            ; d1=hd res size
  141.     move.l    (RT_ENDSKIP,a5),d2
  142.     movem.l    (sp),d0/a0-a1
  143.     sub.l    a1,d2
  144.     add.l    a0,d2
  145.     sub.l    a5,d2            ; d2=td res size
  146.     cmp.l    d2,d1
  147.     bhi    .baddie            ; if hd>td fail!
  148.  
  149. BUFSIZE    EQU    512
  150.     lea    (-BUFSIZE,sp),sp
  151. .scan    move.l    d4,d1            ; Scan backwards for HUNK_RELOC32:
  152.     moveq    #-8,d2            ; This is *really* heavy magic...
  153.     moveq    #OFFSET_CURRENT,d3
  154.     call    Seek
  155.     tst.l    d0
  156.     bmi.b    .baddie2
  157.     move.l    d4,d1
  158.     move.l    sp,d2
  159.     moveq    #4,d3
  160.     call    Read
  161.     cmp.l    d0,d3
  162.     bne.b    .baddie2
  163.     cmp.l    #HUNK_RELOC32,(sp)
  164.     bne.b    .scan
  165.  
  166.     move.l    d4,d1            ; Read reloc table
  167.     move.l    sp,d2
  168.     move.l    #BUFSIZE,d3
  169.     call    Read
  170.     tst.l    d0
  171.     bmi.b    .baddie2
  172.  
  173.     move.l    sp,a0
  174.     move.l    (a0)+,d0        ; d0=number of relocs
  175.     tst.l    (a0)+            ; Must be hunk0 relocs!
  176.     bne.b    .scan
  177.     move.l    d0,d1
  178.     lsl.l    #2,d1
  179.     tst.l    (a0,d1.l)        ; Must be only relocs!
  180.     bne.b    .scan
  181.  
  182.     move.l    (RT_ENDSKIP,a2),d3
  183.     sub.l    a2,d3            ; d3=hd res size
  184.  
  185.     subq.l    #1,d0            ; ReRelocate :)
  186.     move.l    a2,d1
  187.     sub.l    (BUFSIZE+2*4,sp),d1
  188.     add.l    (BUFSIZE+1*4,sp),d1
  189.     sub.l    a5,d1
  190. .subl    move.l    (a0)+,d2
  191.     sub.l    d1,(a2,d2.l)
  192.     dbf    d0,.subl
  193.  
  194.     move.l    a2,a0            ; Copy it!
  195.     move.l    a5,a1
  196.     move.b    (RT_VERSION,a1),(RT_VERSION,a0)
  197.     move.b    (RT_PRI,a1),(RT_PRI,a0)
  198.     move.l    d3,d0
  199.     exg    d6,a6
  200.     call    CopyMem
  201.     exg    d6,a6
  202.  
  203. ; As a side remark: This "loadseg-scanbackforrelocs-rerelocate-copy" 
  204. ; -code worked at first try! Honestly I didn't think it would... ;)
  205.  
  206.     moveq    #1,d7            ; Succeed!
  207.  
  208. .baddie2    lea    (BUFSIZE,sp),sp
  209.  
  210. .baddie    lea    (freefunc,pc),a1
  211.     move.l    d5,d1
  212.     call    InternalUnLoadSeg
  213.  
  214. .close    move.l    d4,d1
  215.     call    Close
  216.  
  217. .exit    exg    d6,a6
  218.     move.l    d7,d0            ; Valid counter?
  219.     bne.b    .xit
  220.     lea    (_error1,pc),a0        ; a0=fmt
  221.     pea    (_hddname,pc)
  222. .fail    move.l    sp,a1            ; a1=array
  223.     jsr    (a4)            ; Call _Printf
  224.     addq.l    #4,sp
  225.     moveq    #0,d0            ; Return fail
  226. .xit    lea    (3*4,sp),sp
  227.     rts
  228.  
  229. .perr    lea    (_error2,pc),a0
  230.     pea    (_hdiname,pc)
  231.     bra.b    .fail    
  232.  
  233.  
  234. funcs    dc.l    readfunc
  235.     dc.l    allocfunc
  236.     dc.l    freefunc
  237.  
  238. readfunc    jmp    (_LVORead,a6)
  239. allocfunc    jmp    (_LVOAllocMem,a6)
  240. freefunc    jmp    (_LVOFreeMem,a6)
  241.  
  242.  
  243. _tdname    dc.b    'trackdisk.device',0
  244. _hdiname    EQU    *+5
  245. _hddname    dc.b    'devs:hackdisk.device',0
  246.  
  247. _error1    dc.b    'Couldn''t load "%s"!',10,0
  248. _error2    dc.b    'Couldn''t utilize this %s version!',10,0
  249.  
  250.  
  251.     SECTION    VERSION,DATA
  252.  
  253.     dc.b    '$VER: hackdisk_PATCH 1.1 (4.5.97)',0
  254.